Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Sep 25, 2025

Summary
This PR introduces an intention action that allows batch conversion between @Sql annotations and SQL files at the DAO class level.

Execution Conditions
The action is available only when:

  • The target class is a DAO class, and

  • At least one method meets the conversion conditions:

    • Methods annotated with @Sql, or
    • Methods that have a corresponding SQL file.

Details

  • Methods already containing an @Sql annotation are excluded from processing. They will not be formatted automatically, and require manual execution of the format action.
  • Conversion to @Sql annotations: The corresponding SQL file is formatted first (for performance reasons), and then the formatted content is injected into the annotation.
  • Conversion to SQL files: After generating the SQL file, a formatting pass is applied to the file.

Injection SQL Handling
When formatting large SQL strings (e.g., injected SQL with ~1000 lines) within @Sql annotations, errors could occur.
To address this:

  • SqlFormatPreProcessor no longer runs on injected SQL.
  • Instead, formatting for injected SQL is handled only by explicitly calling the main logic from SqlInjectionPostProcessor.

Impact

  • Enables efficient class-level batch conversion between annotations and SQL files.
  • Ensures formatting consistency during conversions.
  • Improves stability when handling large injected SQL strings.

@xterao xterao requested a review from Copilot September 25, 2025 04:02
@xterao xterao self-assigned this Sep 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

A comprehensive implementation of bulk conversion functionality between @Sql annotations and SQL files at the DAO class level, with improved SQL formatting stability for large injected SQL strings.

Key changes include:

  • Added two new intention actions for bulk conversion operations on DAO classes
  • Enhanced SQL formatting processors with improved PSI-safe processing and injection handling
  • Updated test suite with comprehensive test coverage for bulk conversion scenarios

Reviewed Changes

Copilot reviewed 62 out of 62 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
BulkConvertSqlAnnotationToFileAction.kt Core implementation for bulk @SQL annotation to SQL file conversion
BulkConvertSqlFileToAnnotationAction.kt Core implementation for bulk SQL file to @SQL annotation conversion
SqlFormatPreProcessor.kt Major refactoring with PSI-safe fast processing and improved injection handling
SqlInjectionPostProcessor.kt Updated to handle formatting for injected SQL with explicit main logic calls
SqlAnnotationConverter.kt Enhanced annotation creation with proper indentation and formatting
Test files (*.sql, *.java) Comprehensive test data for bulk conversion scenarios
Bundle properties Localization support for new bulk conversion actions
plugin.xml Registration of new intention actions with proper ordering

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@xterao xterao added this to the 2.4.0 Release milestone Sep 25, 2025
@xterao xterao linked an issue Sep 25, 2025 that may be closed by this pull request
@xterao xterao changed the title Batch Conversion Action Between @Sql Annotations and SQL Files Batch Conversion Action Between Sql Annotations and SQL Files Sep 25, 2025
@xterao xterao merged commit a0d8140 into main Sep 25, 2025
5 checks passed
@xterao xterao deleted the feature/sql-annotation-file-bulk-convert branch September 25, 2025 05:33
@xterao xterao linked an issue Sep 26, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reformat Code fails with PluginException: VirtualFileWindow is invalid Extend Support for Conversion Between Sql Annotations and SQL Files

3 participants